#!/bin/bash
echo ""
echo "Welcome to DicomScience"
echo ""
if [ -z "$1" ]
then
	echo "ERROR: * Paramters secified *"
	echo "Usage: dsweb start | stop | status"
	echo "EXITING"
	exit
elif [ "$1" == "start" ]
then
	echo "Terminating possible zombie-processes of storescp"
	kill -9 `ps -elf |grep -i storescp | awk '{print $4}'`
	echo ""
	mkdir /tmpp/dicomscience_tmp
	echo "Starting STORESCP"
	echo "(Module to accept DICOM store-connections from all STORESCUs)"
	storescp -od /tmp/dicomscience_tmp -aet DICOMSCIENCE 2008 &
	echo "Starting ScriptEngine to process all incoming DICOM data"
	/usr/dicomscience/bin/dsweb.pl -w &
	echo "Starting movieBot"
	/usr/dicomscience/bin/img2movie.pl -w &
elif [ "$1" == "stop" ]
then
	echo "Terminating all child processes..."
	echo "Killing storescp"
	kill -9 `ps -elf | grep -i storescp | awk '{print $4}'`
	echo "Killing dsweb.pl"
	kill -9 `ps -elf | grep -i dsweb | awk '{print $4}'`
elif [ "$1" == "status" ]
then
	echo "Checking if child-processes are alive.."
	ps auxw | grep -i storescp
	ps auxw | grep -i dsweb.pl
else
	echo "*"
	echo "ERROR: * Uncaught Exception *"
	echo "EXITING"
fi